/**
 * Created by cjd on 2016/5/10.
 */
angular.module("app").controller("group.list.Ctrl", ["$scope", "group", "$timeout", function ($scope, group, $timeout) {
    $scope.groupGridConfig = {
        bindingOptions: {
            selectedRowKeys: "selectedItems",
            dataSource: "groupGridConfig.dataSource"
        },
        twoWayBindingEnabled: false,
        searchPanel: {
            visible: true,
            width: 200,
            placeholder: "输入关键字进行查询"
        },
        paging: {
            pageSize: 15
        },
        groupPanel: {
            visible: true,
            emptyPanelText: "拖动列名进行分组和排序"
        },
        hoverStateEnabled: true,
        showBorders: true,
        showRowLines: true,
        rowAlternationEnabled: true,
        noDataText: "没有数据",
        columns: [{
            dataField: "name",
            alignment: "center",
            caption: "社团名称"
        }, {
            dataField: "times",
            alignment: "center",
            caption: "公益时间"
        }, {
            dataField: "volunteers",
            alignment: "center",
            width:80,
            caption: "成员数量"
        }, {
            dataField: "actvitys",
            alignment: "center",
            width:80,
            caption: "活动数量"
        }, {
            dataField: "monitor",
            alignment: "center",
            caption: "负责人"
        }, {
            dataField: "phone",
            alignment: "center",
            caption: "联系电话"
        }, {
            dataField: "delStatus",
            alignment: "center",
            width:60,
            cellTemplate: "statusCellTemplate",
            caption: "状态"
        }, {
            dataField: "operation",
            alignment: "center",
            cellTemplate: "operationCellTemplate",
            caption: "操作"
        }]
    };
    $scope.orgParent = $scope.$parent.treeViewDataSource[0].orgId;
    $scope.getList = function (orgId) {
        group.listByOrg({}, {orgId: orgId}, function (data) {
            if (data.statusCode == 0) {
                $scope.groupGridConfig.dataSource = data.data;
            }
        });
    };
    $scope.treeViewConfig = angular.copy($scope.$parent.treeViewConfig);
    $scope.treeViewConfig.onItemClick = function (e) {
        $scope.getList(e.itemData.orgId);
        $scope.orgParent = e.itemData.orgId;
        $scope.groupInfo = {};
    };

    $scope.showGroupInfo = function (groupInfo) {
        $scope.groupInfo = groupInfo;
    };
    $scope.showVolunteerList = function (groupInfo) {
        location.href = "#/home/group/volunteerList/" + groupInfo.id;
    };
    $scope.getList($scope.$parent.treeViewDataSource[0].orgId);
}]);